package com.fsharemobile.fragments;

import com.fsharemobile.LoginActivity;
import com.fsharemobile.R;
import com.fsharemobile.model.User;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class SettingFragment extends Fragment implements OnClickListener {

	TextView txtLinkFshare;
	Button btnLogin;
	User myUser;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = (LinearLayout) inflater.inflate(R.layout.fragment_setting, container, false);
		return view;
	}
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		txtLinkFshare =(TextView) getActivity().findViewById(R.id.txt_contact_us);
		btnLogin = (Button)  getActivity().findViewById(R.id.btn_login);
		if(txtLinkFshare!=null){
			txtLinkFshare.setMovementMethod(LinkMovementMethod.getInstance());
		}
		Bundle mDataUser= getActivity().getIntent().getExtras();
        myUser=mDataUser.getParcelable("user");
        if(myUser!=null){
        	Toast.makeText(getActivity(), myUser.getName() , Toast.LENGTH_SHORT).show();
        }
        
        btnLogin.setOnClickListener(this);
        
        
        
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v.getId()==R.id.btn_login){
			
			AlertDialog.Builder loginOrNot= new AlertDialog.Builder(getActivity());
			loginOrNot.setTitle("LOGIN").setIcon(R.drawable.ic_question).setMessage("Do you want to login?");
			
			loginOrNot.setNegativeButton("No", new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					dialog.dismiss();
				}
			});
			
			
			loginOrNot.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					Intent loginIntent= new Intent(getActivity(), LoginActivity.class);
					loginIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
					startActivity(loginIntent);
				}
			});
			
			
			AlertDialog myDialog  = loginOrNot.create();
			
			myDialog.show();
			myDialog.getWindow().setLayout(500, 400);
			
			
		}
	}
	
	
	
	

}
